strikes_agg$city_match
strikes_agg$city_match <- NA
for(i in 1:nrow(strikes_agg)){
strikes_agg$city_match[i] <- kaifaqu$prov_city[amatch(strikes_agg$prov_city[i], kaifaqu$prov_city, maxDist=1)]
}
strikes_agg$city_match
strikes_agg$city_match <- NA
for(i in 1:nrow(strikes_agg)){
strikes_agg$city_match[i] <- kaifaqu$prov_city[amatch(strikes_agg$prov_city[i], kaifaqu$prov_city, maxDist=2)]
}
strikes_agg$city_match
strikes_agg$city_match <- NA
for(i in 1:nrow(strikes_agg)){
strikes_agg$city_match[i] <- kaifaqu$prov_city[amatch(strikes_agg$prov_city[i], kaifaqu$prov_city, maxDist=3)]
}
length(is.na(strikes_agg$city_match))
strikes_agg$city_match
for(i in 1:nrow(strikes_agg)){
strikes_agg$city_match[i] <- kaifaqu$prov_city[amatch(strikes_agg$prov_city[i], kaifaqu$prov_city, maxDist=5)]
}
length(is.na(strikes_agg$city_match))
strikes_agg$city_match <- NA
for(i in 1:nrow(strikes_agg)){
strikes_agg$city_match[i] <- kaifaqu$prov_city[amatch(strikes_agg$prov_city[i], kaifaqu$prov_city, maxDist=5)]
}
length(is.na(strikes_agg$city_match))
strikes_agg$city_match
length(is.na(strikes_agg$city_match)==TRUE)
length(which(is.na(strikes_agg$city_match)==TRUE))
kaifaqu2 <-  merge(kaifaqu, strikes_agg, by.x = c("prov_city", "year"), by.y = c("city_match", "year"),all.x = T)
kaifaqu2 <-  merge(kaifaqu, strikes_agg, by.x = c("prov_city", "year"), by.y = c("city_match", "year"),all.x = T, all.y=FALSE)
kaifaqu2 <-  merge(kaifaqu, strikes_agg, by.x = c("prov_city", "year"), by.y = c("city_match", "year"),all.x = T, all.y=FALSE)
strikes_agg$city_match <- NA
for(i in 1:nrow(strikes_agg)){
strikes_agg$city_match[i] <- kaifaqu$prov_city[amatch(strikes_agg$prov_city[i], kaifaqu$prov_city, maxDist=3)]
}
length(which(is.na(strikes_agg$city_match)==TRUE))
kaifaqu2 <-  merge(kaifaqu, strikes_agg, by.x = c("prov_city", "year"), by.y = c("city_match", "year"),all.x = T, all.y=FALSE)
strikes_agg$city_match
strikes_agg$city_match <- NA
for(i in 1:nrow(strikes_agg)){
strikes_agg$city_match[i] <- kaifaqu$prov_city[amatch(strikes_agg$prov_city[i], kaifaqu$prov_city, maxDist=2)]
}
length(which(is.na(strikes_agg$city_match)==TRUE))
kaifaqu2 <-  merge(kaifaqu, strikes_agg, by.x = c("prov_city", "year"), by.y = c("city_match", "year"),all.x = TRUE, all.y=FALSE)
?join
strikes_agg$prov_city <- strikes_agg$city_match
kaifaqu2 <-  join(kaifaqu, strikes_agg, by =  c("prov_city", "year"))
kaifaqu2 <-  join(kaifaqu, strikes_agg, by =  c("prov_city", "year"))
kaifaqu2$prov_city
kaifaqu$prov_city_year
kaifaqu$prov_city_year
which(duplicated(kaifaqu$prov_city_year)==TRUE)
kaifaqu2$prov_city_yearwhich(duplicated(kaifaqu2$prov_city_year)==TRUE)
kaifaqu2$prov_city_year
kaifaqu2$prov_city_year[which(duplicated(kaifaqu2$prov_city_year)==TRUE)]
length(kaifaqu2$prov_city_year[which(duplicated(kaifaqu2$prov_city_year)==TRUE)])
5816-49
5816-49/2
?merge
kaifaqu$prov_city_year[which(duplicated(kaifaqu$prov_city_year)==TRUE)]
kaifaqu2$prov_city_year[which(duplicated(kaifaqu2$prov_city_year)==TRUE)]
sum(duplicated(kaifaqu2$prov_city_year)==TRUE)
paste(kaifaqu$cityCN, kaifaqu2$province)
paste(kaifaqu$cityCN, kaifaqu$province, kaifaqu$year, sep="_")
sum(duplicated(paste(kaifaqu$cityCN, kaifaqu$province, kaifaqu$year, sep="_")))
which(duplicated(paste(kaifaqu$cityCN, kaifaqu$province, kaifaqu$year, sep="_")))
kaifaqu$cityCN[which(duplicated(paste(kaifaqu$cityCN, kaifaqu$province, kaifaqu$year, sep="_")))]
kaifaqu$cityCN[which(duplicated(paste(kaifaqu$cityPY, kaifaqu$provPY, kaifaqu$year, sep="_")))]
which(duplicated(paste(kaifaqu$cityPY, kaifaqu$provPY, kaifaqu$year, sep="_")))
strikes_agg$prov_city_year <- paste(strikes_agg$city_match, strikes_agg$year)
strikes_agg$prov_city_year
sum(duplicated(strikes_agg$prov_city_year))
strikes_agg$prov_city_year
length(which(is.na(strikes_agg$city_match)==TRUE))
strikes_agg$prov_city_year[which(is.na(strikes_agg$city_match)==TRUE)]
strikes_agg$prov_city_year[which(is.na(strikes_agg$city_match)==TRUE)] <- NA
sum(duplicated(strikes_agg$prov_city_year))
strikes_agg_final <- strikes_agg[is.na(strikes_agg$prov_city_year)==FALSE,]
kaifaqu2 <-  merge(kaifaqu, strikes_agg_final, by = c("prov_city_year"),all.x = TRUE, all.y=FALSE)
sum(kaifaqu2$strikes, na.rm=T)
kaifaqu2$strikes
strikes_agg_final
strikes_agg_final$strikes
names(kaifaqu2)
kaifaqu2$strikes
head(strikes_agg)
strikes_agg$prov_city_year <- paste(strikes_agg$city_match, strikes_agg$year, sep="_")
strikes_agg$prov_city_year[which(is.na(strikes_agg$city_match)==TRUE)] <- NA
strikes_agg$prov_city_year
sum(duplicated(strikes_agg$prov_city_year))
strikes_agg_final <- strikes_agg[is.na(strikes_agg$prov_city_year)==FALSE,]
kaifaqu2 <-  merge(kaifaqu, strikes_agg_final, by = c("prov_city_year"),all.x = TRUE, all.y=FALSE)
which(duplicated(paste(kaifaqu$cityPY, kaifaqu$provPY, kaifaqu$year, sep="_")))
sum(kaifaqu2$strikes, na.rm=T)
kaifaqu2$prov_city_year[which(duplicated(kaifaqu2$prov_city_year)==TRUE)]
kaifaqu2$prov_city_year[which(duplicated(kaifaqu2$prov_city_year)==TRUE)]
kaifaqu$prov_city_year[which(duplicated(kaifaqu$prov_city_year)==TRUE)]
kaifaqu[which(duplicated(kaifaqu$prov_city_year)==TRUE),]
kaifaqu[which(duplicated(kaifaqu$prov_city_year)==TRUE),] <- NULL
kaifaqu[which(duplicated(kaifaqu$prov_city_year)),] <- NULL
kaifaqu[complete.cases(kaifaqu$prov_city_year), ]
kaifaqu3 <- kaifaqu[complete.cases(kaifaqu$prov_city_year), ]
kaifaqu$prov_city_year[which(duplicated(kaifaqu$prov_city_year)==TRUE)]
kaifaqu$city
kaifaqu$cityCN
which(kaifaqu$cityCN=="")
kaifaqu3 <- kaifaqu[which(kaifaqu$cityCN!=""),]
rm(kaifaqu3)
kaifaqu2 <-  merge(kaifaqu, strikes_agg_final, by = c("prov_city_year"),all.x = TRUE, all.y=FALSE)
kaifaqu2$prov_city_year[which(duplicated(kaifaqu2$prov_city_year)==TRUE)]
strikes_agg_final$prov_city_year[which(duplicated(strikes_agg_final$prov_city_year)==TRUE)]
strikes_agg_final <- strikes_agg_final[!duplicated(strikes_agg_final$prov_city_year),]
kaifaqu2 <-  merge(kaifaqu, strikes_agg_final, by = c("prov_city_year"),all.x = TRUE, all.y=FALSE)
sum(kaifaqu2$strikes)
kaifaqu2$strikes
sum(kaifaqu2$strikes, na.rm=TRUE)
kaifaqu <-  merge(kaifaqu, strikes_agg_final, by = c("prov_city_year"),all.x = TRUE, all.y=FALSE)
kaifaqu$strikes[which(kaifaqu$year>2010&is.na(kaifaqu$strikes)==TRUE)] <- 0
kaifaqu$strikes_manufacturing[which(kaifaqu$year>2010&is.na(kaifaqu$strikes_manufacturing)==TRUE)] <- 0
kaifaqu$strikes_services[which(kaifaqu$strikes_services>2010&is.na(kaifaqu$strikes_services)==TRUE)] <- 0
kaifaqu$strikes_education[which(kaifaqu$year>2010&is.na(kaifaqu$strikes_education)==TRUE)] <- 0
kaifaqu$strikes_hightech[which(kaifaqu$year>2010&is.na(kaifaqu$strikes_hightech)==TRUE)] <- 0
kaifaqu$protest_fraud[which(kaifaqu$year>2010&is.na(kaifaqu$protest_fraud)==TRUE)] <- 0
export(kaifaqu, file="~/Dropbox/ResearchProjects/Made in China/trade_kaifaqu_v22.dta")
export(kaifaqu, file="~/Dropbox/ResearchProjects/Made in China/trade_kaifaqu_v22.dta")
names(kaifaqu)
?gsub
gsub(".", "_", names(kaifaqu))
gsub("\.\", "_", names(kaifaqu))
gsub("/./", "_", names(kaifaqu))
gsub("/.", "_", names(kaifaqu))
gsub("\\.", "_", names(kaifaqu))
names(kaifaqu) <- gsub("\\.", "_", names(kaifaqu))
export(kaifaqu, file="~/Dropbox/ResearchProjects/Made in China/trade_kaifaqu_v22.dta")
kaifaqu$year_X
kaifaqu$yearX
kaifaqu$year_X
kaifaqu$year
names(kaifaqu)
kaifaqu$year_x
kaifaqu$year_y <- NULL
kaifaqu$year_y
which(names(kaifaqu)==year_y)
which(names(kaifaqu)=="year_y")
names(kaifaqu)
which(names(kaifaqu)=="year_x")
<- names(which(names(kaifaqu)=="year_x"))
rename(kaifaqu, year=year_x)
kaifaqu <- rename(kaifaqu, year=year_x)
kaifaqu$year
export(kaifaqu, file="~/Dropbox/ResearchProjects/Made in China/trade_kaifaqu_v22.dta")
names(strikes$`Sub Industry`)
unique(strikes$`Sub Industry`)
sort(table((strikes$`Sub Industry`)))
strikes$lumpen <- 0
strikes$lumpen <- 0
strikes$lumpen[which(strikes$`Sub Industry`=="Taxi")] <- 1
strikes$lumpen[which(strikes$`Sub Industry`=="Bus and coach")] <- 1
strikes$lumpen[which(strikes$`Sub Industry`=="Courier")] <- 1
strikes$lumpen[which(strikes$`Sub Industry`=="Food delivery ")] <- 1
strikes$lumpen[which(strikes$`Sub Industry`=="Sports and leisure including spa, nail salon etc ")] <- 1
strikes$lumpen[which(strikes$`Sub Industry`=="Sanitation workers")] <- 1
strikes$lumpen
strikes_agg <- strikes %>%
group_by(prov_city,  year) %>%
dplyr::summarise(strikes=sum(strikes),
strikes_manufacturing=sum(manufacturing),
strikes_services=sum(services),
strikes_education=sum(education),
strikes_hightech=sum(electronics),
strikes_lumpen=sum(lumpen))
strikes_agg$prov_city_year <- paste(strikes_agg$prov_city, strikes_agg$year, sep="_")
temp <- stringdist_left_join(kaifaqu, strikes_agg, by = "prov_city_year", max_dist = 2)
strikes_agg$city_match <- NA
for(i in 1:nrow(strikes_agg)){
strikes_agg$city_match[i] <- kaifaqu$prov_city[amatch(strikes_agg$prov_city[i], kaifaqu$prov_city, maxDist=2)]
}
strikes_agg$prov_city <- strikes_agg$city_match
strikes_agg$prov_city_year <- paste(strikes_agg$city_match, strikes_agg$year, sep="_")
strikes_agg$prov_city_year[which(is.na(strikes_agg$city_match)==TRUE)] <- NA
sum(duplicated(strikes_agg$prov_city_year))
strikes_agg$prov_city_year
paste(strikes_agg$city_match, strikes_agg$year, sep="_")
strikes_agg$city_match
strikes_agg$city_match <- NA
for(i in 1:nrow(strikes_agg)){
strikes_agg$city_match[i] <- kaifaqu$prov_city[amatch(strikes_agg$prov_city[i], kaifaqu$prov_city, maxDist=2)]
}
kaifaqu$prov_city
kaifaqu$prov_city <- paste(kaifaqu$provPY, kaifaqu$cityPY, sep="_")
kaifaqu$prov_city_year <- paste(kaifaqu$provPY, kaifaqu$cityPY, kaifaqu$year, sep="_")
strikes_agg$city_match <- NA
for(i in 1:nrow(strikes_agg)){
strikes_agg$city_match[i] <- kaifaqu$prov_city[amatch(strikes_agg$prov_city[i], kaifaqu$prov_city, maxDist=2)]
}
strikes_agg$city_match
kaifaqu$prov_city
strikes_agg$prov_city
strikes_agg <- strikes %>%
group_by(prov_city,  year) %>%
dplyr::summarise(strikes=sum(strikes),
strikes_manufacturing=sum(manufacturing),
strikes_services=sum(services),
strikes_education=sum(education),
strikes_hightech=sum(electronics),
strikes_lumpen=sum(lumpen))
kaifaqu$prov_city <- paste(kaifaqu$provPY, kaifaqu$cityPY, sep="_")
kaifaqu$prov_city_year <- paste(kaifaqu$provPY, kaifaqu$cityPY, kaifaqu$year, sep="_")
strikes_agg$prov_city_year <- paste(strikes_agg$prov_city, strikes_agg$year, sep="_")
paste(strikes_agg$prov_city, strikes_agg$year, sep="_")
strikes_agg$prov_city_year <- paste(strikes_agg$prov_city, strikes_agg$year, sep="_")
strikes_agg$city_match <- NA
for(i in 1:nrow(strikes_agg)){
strikes_agg$city_match[i] <- kaifaqu$prov_city[amatch(strikes_agg$prov_city[i], kaifaqu$prov_city, maxDist=2)]
}
strikes_agg$city_match
strikes_agg$prov_city <- strikes_agg$city_match
strikes_agg$prov_city_year
strikes_agg$prov_city_year[which(is.na(strikes_agg$city_match)==TRUE)]
strikes_agg$city_match
strikes_agg$prov_city_year[which(is.na(strikes_agg$city_match)==TRUE)] <- NA
sum(duplicated(strikes_agg$prov_city_year))
strikes_agg_final <- strikes_agg[is.na(strikes_agg$prov_city_year)==FALSE,]
strikes_agg_final <- strikes_agg_final[!duplicated(strikes_agg_final$prov_city_year),]
kaifaqu <- kaifaqu[which(kaifaqu$cityCN!=""),]
names(kaifaqu)
kaifaqu <- import("~/Dropbox/ResearchProjects/Made in China/trade_kaifaqu_v20.dta")
kaifaqu <- import("~/Dropbox/ResearchProjects/Made in China/trade_kaifaqu_v21.dta")
kaifaqu$cityPY <- stri_trans_general(py(kaifaqu$cityCN, sep = ""),"Latin-ASCII")
#Remove  word prov
kaifaqu$province <- str_replace(kaifaqu$province, "省", "")
#Only first 2 characters of Chinese prov names
kaifaqu$provPY <- substr(kaifaqu$province, 1, 2)
#Chinese city name to pinyin without  accents
kaifaqu$provPY <- stri_trans_general(py(kaifaqu$provPY, sep = ""),"Latin-ASCII")
kaifaqu$provPY[which(kaifaqu$provPY =="hena")] <- "henan"
kaifaqu$provPY[which(kaifaqu$provPY =="haina")] <- "hainan"
kaifaqu$provPY[which(kaifaqu$provPY =="heilong")] <- "heilongjiang"
kaifaqu$provPY[which(kaifaqu$provPY =="yunna")] <- "yunnan"
kaifaqu$provPY[which(kaifaqu$provPY =="huna")] <- "hunan"
kaifaqu$provPY[which(kaifaqu$provPY =="anxi")] <- "guangxi"
kaifaqu$provPY[which(kaifaqu$provPY =="nameng")] <- "neimenggu"
kaifaqu$provPY[which(kaifaqu$provPY =="andong")] <- "guangdong"
kaifaqu$provPY[which(kaifaqu$provPY =="jinghai")] <- "qinghai"
kaifaqu$provPY[which(kaifaqu$provPY =="ningjia")] <- "ningxia"
kaifaqu$provPY[which(kaifaqu$provPY =="xicang")] <- "xizang"
kaifaqu$prov_city <- paste(kaifaqu$provPY, kaifaqu$cityPY, sep="_")
kaifaqu$prov_city_year <- paste(kaifaqu$provPY, kaifaqu$cityPY, kaifaqu$year, sep="_")
kaifaqu <- kaifaqu[which(kaifaqu$cityCN!=""),]
names(kaifaqu)
kaifaqu2 <-  merge(kaifaqu, strikes_agg_final, by = c("prov_city_year"),all.x = TRUE, all.y=FALSE)
kaifaqu <-  merge(kaifaqu, strikes_agg_final, by = c("prov_city_year"),all.x = TRUE, all.y=FALSE)
kaifaqu$strikes[which(kaifaqu$year>2010&is.na(kaifaqu$strikes)==TRUE)] <- 0
kaifaqu$strikes_manufacturing[which(kaifaqu$year>2010&is.na(kaifaqu$strikes_manufacturing)==TRUE)] <- 0
kaifaqu$strikes_services[which(kaifaqu$strikes_services>2010&is.na(kaifaqu$strikes_services)==TRUE)] <- 0
kaifaqu$strikes_education[which(kaifaqu$year>2010&is.na(kaifaqu$strikes_education)==TRUE)] <- 0
kaifaqu$strikes_hightech[which(kaifaqu$year>2010&is.na(kaifaqu$strikes_hightech)==TRUE)] <- 0
kaifaqu$protest_fraud[which(kaifaqu$year>2010&is.na(kaifaqu$protest_fraud)==TRUE)] <- 0
kaifaqu$year_x <- NULL
kaifaqu <- rename(kaifaqu, year=year_y)
kaifaqu <- rename(kaifaqu, year=year_x)
kaifaqu$year
names(kaifaqu) <- gsub("\\.", "_", names(kaifaqu))
kaifaqu$year_y <- NULL
kaifaqu <- rename(kaifaqu, year=year_x)
export(kaifaqu, file="~/Dropbox/ResearchProjects/Made in China/trade_kaifaqu_v22.dta")
kaifaqu$strikes[which(kaifaqu$year>2010&is.na(kaifaqu$strikes)==TRUE)]
kaifaqu$strikes[which(kaifaqu$year>2010&is.na(kaifaqu$strikes)==TRUE)] <- 0
kaifaqu$strikes_manufacturing[which(kaifaqu$year>2010&is.na(kaifaqu$strikes_manufacturing)==TRUE)] <- 0
kaifaqu$strikes_services[which(kaifaqu$strikes_services>2010&is.na(kaifaqu$strikes_services)==TRUE)] <- 0
kaifaqu$strikes_education[which(kaifaqu$year>2010&is.na(kaifaqu$strikes_education)==TRUE)] <- 0
kaifaqu$strikes_hightech[which(kaifaqu$year>2010&is.na(kaifaqu$strikes_hightech)==TRUE)] <- 0
kaifaqu$protest_fraud[which(kaifaqu$year>2010&is.na(kaifaqu$protest_fraud)==TRUE)] <- 0
export(kaifaqu, file="~/Dropbox/ResearchProjects/Made in China/trade_kaifaqu_v22.dta")
prisoners <- import("~/Downloads/xufiles/Political Prisoner Data/county05_15.dta")
head(prisoners)
secdat <- import("~/Downloads/xufiles/94_030607security.dta")
secdat <- import("~/Downloads/xufiles/County Fiscal Data/94_030607security.dta")
head(secdat)
secdat$admcode
unique(secdat$admcode)
which(secdat$admcode=="340800")
secdat$year[which(secdat$admcode=="340800")]
rm(list=ls())
dat <- import("~/Dropbox/Data/Religion/Data/Current/data_nationalism_v_13.xlsx")
require("rio")
require("rio")
dat <- import("~/Dropbox/Data/Religion/Data/Current/data_nationalism_v_13.xlsx")
dat <- dat[, c("tmh.dummy", "tmh", "tmh.ln", "nationalist.post05", "nationalist.post05.total", "nationalist.post05.ln",
"china_inland_mission_1865", "china_inland_mission_ln", "china_inland_mission_dummy",
"conflict_total", "conflict_ln", "conflict_dummy", "pop_int", "pop_int_ln", "treaty",
"size", "size_ln", "coast", "lnrailwaydist", "newspapers", "newspapers.ln", "quota", "quota1840",
"books.total", "books.total.ln", "books.politics", "books.politics.ln", "books.foreign", "books.foreign.ln",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples", "temples.ln", "fragm")]
dat <- dat[, c("tmh.dummy", "tmh", "nationalist.post05", "nationalist.post05.total",
"china_inland_mission_1865",  "china_inland_mission_dummy",
"conflict_total",  "pop_int",  "treaty",
"size", "size_ln", "coast", "lnrailwaydist", "newspapers",  "quota", "quota1840",
"books.total", "books.politics",  "books.foreign",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples",  "fragm")]
dat$quota <- as.numeric(paste(dat$quota0))
dat$quota <-  as.numeric(paste(dat$quota0))
dat$rankc_p<- as.numeric(paste(dat$rankc_p))
dat$coast <- as.numeric(paste(dat$coast))
dat$size <- as.numeric(paste(dat$size))
dat$stauffer_year_mean
dat <- dat[, c("tmh.dummy", "tmh",  "quota",  "stauffer_year_mean",
"china_inland_mission_1865",  "china_inland_mission_dummy",
"conflict_total",  "pop_int",  "treaty",
"size", "size_ln", "coast", "lnrailwaydist", "newspapers",  "quota", "quota1840",
"books.total", "books.politics",  "books.foreign",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples",  "fragm",
"party_school_9405_main", "other_groups_9405_main", "qingli_post98", "party_school_0511",
"other_groups_0511_main")]
dat2 <- dat
dat <- dat[, c("tmh.dummy", "tmh",  "quota",  "stauffer_year_mean",
"china_inland_mission_1865",  "china_inland_mission_dummy",
"conflict_total",  "pop_int",  "treaty",
"size", "coast", "lnrailwaydist", "newspapers",  "quota", "quota1840",
"books.total", "books.politics",  "books.foreign",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples",  "fragm",
"party_school_9405_main", "other_groups_9405_main", "qingli_post98", "party_school_0511",
"other_groups_0511_main")]
dat <- dat[, c("tmh",  "quota",  "stauffer_year_mean",
"china_inland_mission_1865",  "china_inland_mission_dummy",
"conflict_total",  "pop_int",  "treaty",
"size", "coast", "lnrailwaydist", "newspapers",  "quota", "quota1840",
"books.total", "books.politics",  "books.foreign",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples",  "fragm",
"party_school_9405_main", "other_groups_9405_main", "qingli_post98", "party_school_0511",
"other_groups_0511_main")]
dat <- dat[, c("tmh",  "quota",  "stauffer_year_mean",
"china_inland_mission_1865",
"conflict_total",  "pop_int",  "treaty",
"size", "coast", "lnrailwaydist", "newspapers",  "quota", "quota1840",
"books.total", "books.politics",  "books.foreign",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples",  "fragm",
"party_school_9405_main", "other_groups_9405_main", "qingli_post98", "party_school_0511",
"other_groups_0511_main")]
dat$quota
dat$china_inland_mission_1865
dat$lnrailwaydist
dat$tmh
dat$fragm
dat$fragm <- as.numeric(paste(dat$fragm))
dat <- dat[, c("tmh",  "quota",  "stauffer_year_mean",
"china_inland_mission_1865",
"conflict_total",  "pop_int",  "treaty",
"size", "coast", "lnrailwaydist", "newspapers",  "quota", "quota1840",
"books.total", "books.politics",  "books.foreign",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples",  "fragm",
"party_school_9405_main", "other_groups_9405_main", "qingli_post98", "party_school_0511",
"other_groups_0511_main")]
dat$conflict_total
dat$pop_int
dat$treaty
dat$size
dat$coast
dat$newspapers
dat$quota1840
dat$provid
cbind(dat$provid, dat$prov)
dat$provid[148]
dat$provid[148] <- "12"
names(dat)
names(dat)
dat <- dat[, c( "prov", "prof", "provid", "prefid", "tmh",  "quota",  "stauffer_year_mean",
"china_inland_mission_1865",
"conflict_total",  "pop_int",  "treaty",
"size", "coast", "lnrailwaydist", "newspapers",  "quota",
"books.total", "books.politics",  "books.foreign",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples",  "fragm",
"party_school_9405_main", "other_groups_9405_main", "qingli_post98", "party_school_0511",
"other_groups_0511_main")]
dat$taxpc1820
dat$party_school_9405_main
dat$other_groups_9405_main
dat$qingli_post98
dat$party_school_0511
dat$other_groups_0511_main
dat$conflict_total
dat$treaty
dat[, c( "prov", "prof", "provid", "prefid", "tmh",  "quota",  "stauffer_year_mean",
"china_inland_mission_1865",
"conflict_total",  "pop_int",  "treaty",
"size", "coast", "lnrailwaydist", "newspapers",  "quota",
"books.total", "books.politics",  "books.foreign",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples",  "fragm",
"party_school_9405_main", "other_groups_9405_main", "qingli_post98", "party_school_0511",
"other_groups_0511_main")]
dat$prov
dat$prof
dat$pref
dat <- dat[, c( "prov", "pref", "provid", "prefid", "tmh",  "quota",  "stauffer_year_mean",
"china_inland_mission_1865",
"conflict_total",  "pop_int",  "treaty",
"size", "coast", "lnrailwaydist", "newspapers",  "quota",
"books.total", "books.politics",  "books.foreign",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples",  "fragm",
"party_school_9405_main", "other_groups_9405_main", "qingli_post98", "party_school_0511",
"other_groups_0511_main")]
export(dat, file="~/Desktop/Mattingly Chen JOP Replication/mattingly_chen_data.csv")
dat <- import("~/Desktop/Mattingly Chen JOP Replication/mattingly_chen_data.csv")
dat$quota
dat$quota_ln <- log(dat$quota/dat$pop_int)
dat$pop_int[which(dat$pop_int==0)]
dat$pop_int
dat$missionary_stauffer <- dat$stauffer_year_mean
dat$missionary_stauffer[which(dat$stauffer_year_mean<1905)] <- 1
dat$missionary_stauffer[which(dat$stauffer_year_mean>=1905)] <- 0
dat$missionary_stauffer
dat$other_groups_9405_dummy+dat$party_school_9405_dummy+dat$qingli_post98_dummy+dat$tmh.dummy
dat$temples
dat <- dat2
dat <- dat[, c( "prov", "pref", "provid", "prefid", "tmh",  "quota",  "stauffer_year_mean",
"china_inland_mission_1865",  "jinshi", "rice",
"conflict_total",  "pop_int",  "treaty",
"size", "coast", "lnrailwaydist", "newspapers",  "quota",
"books.total", "books.politics",  "books.foreign",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples",  "fragm",
"party_school_9405_main", "other_groups_9405_main", "qingli_post98", "party_school_0511",
"other_groups_0511_main")]
export(dat, file="~/Desktop/Mattingly Chen JOP Replication/mattingly_chen_data.csv")
dat$quota
min(dat$quota)
min(dat$quota, na.rm+T)
min(dat$quota, na.rm=T)
dat <- dat2
dat$provid[148] <- "12"
dat <- dat[, c( "prov", "pref", "provid", "prefid", "tmh",  "quota",  "stauffer_year_mean",
"china_inland_mission_1865",  "jinshi", "rice",
"conflict_total",  "pop_int",  "treaty",
"size", "coast", "lnrailwaydist", "newspapers",  "quota",
"books.total", "books.politics",  "books.foreign",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples",  "fragm",
"party_school_9405_main", "other_groups_9405_main", "qingli_post98", "party_school_0511",
"other_groups_0511_main",
"stauffer_total_christians",
"stauffer_congregations",
"stauffer_total_primary_mission")]
export(dat, file="~/Desktop/Mattingly Chen JOP Replication/mattingly_chen_data.csv")
dat$area
dat$size
dat$size.ln <- log(dat$size)
dat$other_groups_0511_main+dat$party_school_0511+dat$tmh
dat$taxpc1820
hist(dat$taxpc1820)
hist(log(dat$taxpc1820))
lm1 <- lm(scale(log(taxpc1820))~log(china_inland_mission_1865+1), data=dat)
summary(lm1)
dat$jinshi.ln <- log(dat$jinshi)
dat$jinshi
dat$jinshi <- as.numeric(paste(dat$jinshi))
dat$jinshi.ln <- log(dat$jinshi+1)
lm3 <- lm(jinshi.ln~log(china_inland_mission_1865+1), data=dat)
summary(lm3)
dat$jinshi.ln <- scale(log(dat$jinshi/pop_int+1))
dat$jinshi.cap.ln <- scale(log(dat$jinshi/pop_int+1))
dat$jinshi.cap.ln <- scale(log(dat$jinshi/dat$pop_int+1))
lm3 <- lm(jinshi.cap.ln~log(china_inland_mission_1865+1), data=dat)
summary(lm3)
dat$pop_int/10000
dat$pop_int
dat <- dat2
dat$railwaydist <- 10^dat$lnrailwaydist
dat$railwaydist
dat$railwaydist/1000
dat$railwaydist/1000000
dat$railwaydist/1000000000
dat$railwaydist/1000000000000
dat$railwaydist/10000000000000
dat$railwaydist/100000000
hist(dat$railwaydist/100000000)
hist(dat$railwaydist/1000000000)
hist(dat$railwaydist/10000000000)
hist(dat$railwaydist/100000000000)
dat$railwaydist <- dat$railwaydist/100000000000
dat$railwaydist
dat <- dat[, c( "prov", "pref", "provid", "prefid", "tmh",  "quota",  "stauffer_year_mean",
"china_inland_mission_1865",  "jinshi", "rice",
"conflict_total",  "pop_int",  "treaty",
"size", "coast", "railwaydist", "newspapers",  "quota",
"books.total", "books.politics",  "books.foreign",
"mean_mdf_ds", "taxpc1820", "rankc_p", "temples",  "fragm",
"party_school_9405_main", "other_groups_9405_main", "qingli_post98", "party_school_0511",
"other_groups_0511_main",
"stauffer_total_christians",
"stauffer_congregations",
"stauffer_total_primary_mission")]
export(dat, file="~/Desktop/Mattingly Chen JOP Replication/mattingly_chen_data.csv")
dat$railwaydist
dat$china_inland_mission_1865
rm(list=ls())
setwd('~/Desktop/Mattingly_Chen_JOP_Replication')
packages <- c("AER", "rio", "lmtest", "stargazer", "ggplot2", "sensemakr", "rgdal")
new.packages <- packages[!(packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
rm(packages, new.packages)
require("AER")
require("rio")
require("lmtest")
require("stargazer")
require("ggplot2")
require("sensemakr")
require("rgdal")
dat <- import("Data/mattingly_chen_data.csv")
source("Analysis/Mattingly_Chen_Variable_Creation.R")
source("Analysis/Mattingly_Chen_Main_Tables_Figures.R")
source("Analysis/Mattingly_Chen_Appendix_Tables_Figures.R")
source("Analysis/Mattingly_Chen_Maps.R")
rm(list=ls())
